/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.home.presenter;

import com.baiiu.filter.ClassifyBo;
import com.yiqi.liebang.entity.bo.ExpertBo;
import com.yiqi.liebang.entity.bo.PeopleBo;
import com.yiqi.liebang.entity.bo.SearchFriendBo;
import com.yiqi.liebang.feature.home.contract.ClassifyContract;
import com.yiqi.liebang.feature.home.dependencies.classsify.DaggerClassifyPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class ClassifyPresenter implements ClassifyContract.Presenter {

    private ClassifyContract.View mView;

    @Inject

    ClassifyContract.Model mModel;


    public ClassifyPresenter(ClassifyContract.View mView) {
        this.mView = mView;
        DaggerClassifyPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getClassifyData() {
        mModel.getClassifyData().compose(mView.bindToLife()).subscribe(new Observer<List<ClassifyBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<ClassifyBo> homeBo) {
                mView.dismissLoading();
                mView.showSuccess(homeBo);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });

    }

    @Override
    public void getClassifyExpert(String classifyId,int pageNow,int pageSize) {
        mModel.getClassifyExpert(new ClassifyBo(classifyId, pageNow, pageSize)).compose(mView.bindToLife()).subscribe(new Observer<List<SearchFriendBo.UserFriendBean>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<SearchFriendBo.UserFriendBean> homeBo) {
                mView.dismissLoading();
                if (homeBo!=null&&homeBo.size()>0){
                    mView.showExpert(homeBo);
                }else {
                    mView.showEmpty();
                }

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getUserLabelByType(String useruid) {
        PeopleBo peopleBo=new PeopleBo();
        peopleBo.setUserUid(useruid);
        mModel.getUserLabelByType(peopleBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String homeBo) {
                mView.dismissLoading();
                mView.showUserSuccess(homeBo);

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showUserError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }

    @Override
    public void getQuestionClassify() {
        mModel.getQuestionClassify()
                .compose(mView.bindToLife())
                .subscribe(new Observer<List<ClassifyBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(List<ClassifyBo> classifyBos) {
                     mView.showSuccess(classifyBos);
                    }

                    @Override
                    public void onError(Throwable e) {
                         mView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
